package com.base.app.compon;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.base.app.R;

/**
 * LoadingDialog:自定义dialog
 */

public class TipsDialog extends Dialog {


    TextView text_dialog_tips;
    Button button_cancel;


    /**
     * 按钮之间的分割线
     */
    public TipsDialog(Context context) {
        super(context, R.style.CustomDialog);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_dialog_tips);
        //按空白处不能取消动画
        setCanceledOnTouchOutside(false);

        text_dialog_tips = findViewById(R.id.text_dialog_tips);

        button_cancel = findViewById(R.id.button_cancel);
        button_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onClickBottomListener.onClickCancel();
            }
        });

    }


    @Override
    public void show() {
        super.show();
    }


    /**
     * 设置确定取消按钮的回调
     */
    public OnClickBottomListener onClickBottomListener;
    public TipsDialog setOnClickBottomListener(OnClickBottomListener onClickBottomListener) {
        this.onClickBottomListener = onClickBottomListener;
        return this;
    }

    public interface OnClickBottomListener{
        /**
         * 点击确定按钮事件
         */
        public void onClickCancel();
    }

    public void setText_tips(String msg){
        if(text_dialog_tips!=null){
            text_dialog_tips.setText(msg);
        }
    }


    // 屏蔽返回键
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        //右键返回
        if(keyCode == KeyEvent.KEYCODE_BACK){
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

}
